ENT.Base = "base_entity"
ENT.Type = "brush"

function ENT:Initialize()
	self.Entity:SetName(self.Entity["targetname"])
	if (self.Entity["parentname"]!=nil) then me:SetParent(self.Entity["parentname"]) end
	//self.active=self.Entity:Flag(0)
	self.active=true
	self.activelast=self.activelast
end
function ENT:KeyValue(key, value)
	if (self.Entity:IsOutput(key)) then self.Entity:StoreOutput(key,value)
	else self.Entity[key]=value end
end
function ENT:AcceptInput(i,activator,caller)
	if		(i=="Activate") then
		self.active=true
	elseif	(i=="Deactivate") then
		self.active=false
	end
end

InGoal(true,ent)
function ENT:StartTouch(ent)
	if (self.active) then
		if (ent:IsPlayer() and ent:IsValid() and ent:Alive()) then
			InGoal(true,ent)
			goals.status[ent:UserID()]=true
		end
	end
end
function ENT:EndTouch(ent)
	if (self.active) then
		if (ent:IsPlayer() and ent:IsValid() and ent:Alive()) then
			InGoal(false,ent)
			goals.status[ent:UserID()]=false
		end
	end
end
function ENT:Touch(entity)
end
function ENT:PassesTriggerFilters(entity)
	return true
end
function ENT:KeyValue(key,value)
end
function ENT:Think()
	if (self.active!=self.activelast) then
		self.Entity:ClearPlayers()
		self.activelast=self.active
	end
end
function ENT:OnRemove()
	self.Entity:ClearPlayers()
end

function ENT:ClearPlayers()
	for _, pl in pairs(player.GetAll()) do
		if (pl:IsValid()) then
			InGoal(false,pl)
			goals.status[pl:UserID()]=false
		end
	end
end
function ENT:IsOutput(o)
	local OUTPUTLIST = { "OnActivate", "OnDeactivate" }
	local r=false
	for i in pairs(OUTPUTLIST) do
		if (o==OUTPUTLIST[i]) then return true end
	end
	return false
end
